/**
 * lilang
 * workDto.java
 * 2013-10-18下午3:04:16
 */
package com.cq.oa.domain.dto;

import java.util.ArrayList;
import java.util.List;

import com.cq.oa.domain.wfc.Activity;
import com.cq.oa.domain.wfc.ActivityParticipation;
import com.cq.oa.domain.wfc.ProcessDefinition;
import com.cq.oa.domain.wfc.ProcessJsp;
import com.cq.oa.domain.wfc.Transition;

/**
 * @author lilang
 *
 */
public class WorkDto {
	
	private Long sid;
	
	private ProcessDefinition processDefinition;
	
	
	private List<Activity> activities;
	
	private List<Transition> transitions;
	
	private List<ActivityParticipation> activityParticipations;
	
	private List<ProcessJsp> processJsps;
	
	
	
	/**
	 * 下一步任务处理人    
	 * 
	 */
	private String[] nextTaskOpers;
	

	private String businessId;
	
	private Long taskId;
	
	
	private Long types;
	
	
	
	
	public Long getTypes() {
		return types;
	}

	public void setTypes(Long types) {
		this.types = types;
	}

	public List<ProcessJsp> getProcessJsps() {
		return processJsps;
	}

	public void setProcessJsps(List<ProcessJsp> processJsps) {
		this.processJsps = processJsps;
	}

	public String[] getNextTaskOpers() {
		return nextTaskOpers;
	}

	public void setNextTaskOpers(String[] nextTaskOpers) {
		this.nextTaskOpers = nextTaskOpers;
	}

	public String getBusinessId() {
		return businessId;
	}

	public void setBusinessId(String businessId) {
		this.businessId = businessId;
	}

	public Long getTaskId() {
		return taskId;
	}

	public void setTaskId(Long taskId) {
		this.taskId = taskId;
	}

	public Long getSid() {
		return sid;
	}

	public void setSid(Long sid) {
		this.sid = sid;
	}

	public List<ActivityParticipation> getActivityParticipations() {
		return activityParticipations;
	}

	public void setActivityParticipations(
			List<ActivityParticipation> activityParticipations) {
		this.activityParticipations = activityParticipations;
	}

	public ProcessDefinition getProcessDefinition() {
		return processDefinition;
	}

	public void setProcessDefinition(ProcessDefinition processDefinition) {
		this.processDefinition = processDefinition;
	}

	
	public List<Transition> getTransitions() {
		return transitions;
	}

	public void setTransitions(List<Transition> transitions) {
		this.transitions = transitions;
	}

	public List<Activity> getActivities() {
		return activities;
	}

	public void setActivities(List<Activity> activities) {
		this.activities = activities;
	}
	
	/**
	 * 获取第一个开始节点 node
	 * @return
	 * lilang 
	 * 2013-10-20下午5:27:44
	 */
	public Activity getFristNode(){
		if(activities!=null){
			for(Activity activity:activities){
				if("R".equals(activity.getClazz())){
					return activity;
				}
			}
		}
		return null;
	}
	/**
	 * 设置节点参与人
	 * 
	 * lilang 
	 * 2013-10-25下午1:26:59
	 */
	public void setPartiction(){
		if(activities!=null && activityParticipations!=null){
			for(Activity activity:activities){
				if("U".equals(activity.getClazz())){
					List<ActivityParticipation> participations = new ArrayList<ActivityParticipation>();
					for(ActivityParticipation participation:activityParticipations){
						if(activity.getSid().equals(participation.getActivitySid())){
							participations.add(participation);
						}
					}
					activity.setActivityParticipationList(participations);
				}
				
			}
		}
	}
	/**
	 * 获取当前SID 的节点
	 * @param sid
	 * @return
	 * lilang 
	 * 2013-10-20下午5:37:03
	 */
	public Activity getNode(Long sid){
		if(activities!=null){
			for(Activity activity:activities){
				if(sid.equals(activity.getSid())){
					return activity;
				}
			}
		}
		return null;
	}
	
	/**
	 * 获取当前ID 的下一个ID
	 * @param sid
	 * @return
	 * lilang 
	 * 2013-10-20下午5:40:20
	 */
	public Activity getNextNode(Long sid){
		if(transitions!=null){
			for(Transition transition:transitions){
				if(sid.equals(transition.getFromSid())){
					return this.getNode(transition.getToSid());
				}
			}
		}
		return null;
	}
	
	/**
	 * 获取当前ID 的下一个ID
	 * @param sid
	 * @return
	 * lilang 
	 * 2013-10-20下午5:40:20
	 */
	public List<Activity> getNextNodes(Long sid){
		List<Activity> nodes = new ArrayList<Activity>();
		if(transitions!=null){
			for(Transition transition:transitions){
				if(sid.equals(transition.getFromSid())){
					Activity act = getNode(transition.getToSid());
					if("U".equals(act.getClazz())){
						nodes.add(act);
					}else if("E".equals(act.getClazz())){
						nodes.add(act);
						break;
					}
				}
			}
		}
		return nodes;
	}
	/**
	 * 获取所有 普通节点
	 * @return
	 * lilang 
	 * 2013-10-20下午5:44:59
	 */
	public List<Activity> getAllNodes(){
		List<Activity> list = new ArrayList<Activity>();
		if(activities!=null){
			for(Activity activity:activities){
				if("U".equals(activity.getClazz())){
					list.add(activity);
				}
			}
		}
		return list;
	}
	/**
	 * 取得开始节点
	 * @return
	 * lilang 
	 * 2013-10-26下午2:56:45
	 */
	public Activity getStartNode(){
		Activity activity = this.getFristNode();
		return this.getNextNode(activity.getSid());
	}

}
